<!DOCTYPE HTML>
<html>
<head>
<title>StringTrimLeft / StringTrimRight | AutoHotkey</title>
<meta name="description" content="The StringTrimLeft and StringTrimRight commands remove a number of characters from the left or right-hand side of a string." />
<meta name="ahk:equiv-v2" content="commands/SubStr.htm" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
<script type="text/javascript">$(function(){0<=window.navigator.userAgent.toLowerCase().indexOf("ucbrowser")&&CaoNiMaDeUc()})</script>
</head>
<body>

<h1>StringTrimLeft / StringTrimRight</h1>

<p>从字符串的左边或右边移除一些字符.
</p>

<p class="warning"><strong>不推荐:</strong> 不推荐在新脚本中使用这些命令. 请使用 <a href="SubStr.htm">SubStr</a> 函数作为代替.</p>

<pre class="Syntax">
<span class="func">StringTrimLeft</span>, OutputVar, InputVar, Count
<span class="func">StringTrimRight</span>, OutputVar, InputVar, Count
</pre>
<h2>参数</h2>
<dl>

  <dt>OutputVar</dt>
  <dd><p>用来存储 <em>InputVar</em> 缩短后字符串的变量名.</p></dd>

  <dt>InputVar</dt>
  <dd><p>需要被读取内容的变量名. 不要把名称括在百分号中, 除非您希望使用变量的 <em>内容</em> 作为被解析的变量名.</p></dd>

  <dt>Count</dt>
  <dd><p>需移除的字符数, 可以为<a href="../Variables.htm#Expressions">表达式</a>. 如果 <em>Count</em> 小于或等于零, 那么 <em>OutputVar</em> 会被置为与 <em>InputVar</em> 相同. 如果 <em>Count</em> 超过了 <em>InputVar</em> 的长度, 那么 <em>OutputVar</em> 会被置空.</p></dd>

</dl>

<h2>备注</h2>
<p>在这个及其他所有命令中, <em>OutputVar</em> 和 <em>InputVar</em> 中可以使用相同的变量.</p>
<h2>相关</h2>
<p><a href="SubStr.htm">SubStr()</a>, <a href="StringMid.htm">StringMid</a>, <a href="StringLeft.htm">StringLeft</a>, <a href="StringLeft.htm">StringRight</a>, <a href="IfInString.htm">IfInString</a>, <a href="StringGetPos.htm">StringGetPos</a>, <a href="StringLen.htm">StrLen() / StringLen</a>, <a href="StringLower.htm">StringLower</a>, <a href="StringLower.htm">StringUpper</a>, <a href="StringReplace.htm">StringReplace</a></p>
<h2>示例</h2>
<div class="ex" id="ExBasic">
<p><a href="#ExBasic">#1</a></p>
<pre>String := "This is a test."
StringTrimLeft, OutputVar, String, 5  <em>; 保存字符串 "is a test." 到 OutputVar.</em>
StringTrimRight, OutputVar, String, 6  <em>; 保存字符串 "This is a" 到 OutputVar.</em></pre>
</div>

</body>
</html>